package com.itboye.textileexpres.util;

import android.annotation.SuppressLint;
import android.net.ParseException;

import java.io.ObjectInputStream.GetField;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Observer;

import com.itboye.textileexpes.beans.OrderDeltilteBeans;

/**
 * 
 * @author 格式化时间戳
 * 
 */
public class TimeFormat {
	static String time;

	public static String DateFormat(String s) {
		DateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
		try {
			long ictiime = Long.valueOf(s);
			time = sdf.format(new Date(ictiime * 1000L));
		} catch (Exception e) {
			// TODO: handle exception
		}

		return time;

	}

	public static String getCurrentTime(String format) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
		String currentTime = sdf.format(date);
		return currentTime;
	}

	public static String getCurrentTime() {
		return getCurrentTime("yyyy-MM-dd  HH:mm:ss");
	}

	/**
	 * 获取当前时间
	 * 
	 * @return
	 */
	@SuppressLint("SimpleDateFormat")
	public static String getSimData() {
		SimpleDateFormat sDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd hh:mm");
		String date = sDateFormat.format(new java.util.Date());
		return date;
	}


	
	
	public static String onTime(OrderDeltilteBeans beans) {
		String str=null;
		SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String time = TimeFormat.DateFormat(beans.get_auto_op_time()+"");
		java.util.Date begin = null;
		try {
			begin = dfs.parse(TimeFormat.getSimData());
		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		java.util.Date end = null;
		try {
			end = dfs.parse(time);

		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("PPPPPPPPP"+end.getTime());
		long between = (end.getTime()-begin.getTime()) / 1000;// 除以1000是为了转换成秒

		long day1 = between / (24 * 3600);
		long hour1 = between % (24 * 3600) / 3600;
		long minute1 = between % 3600 / 60;
//		long second1 = between % 60 / 60;
		if (day1 <=0) {
			str="交易已关闭" ;
		} else if(hour1<0){
			str="交易已关闭" ;
		}else if(minute1<=0){
			str="交易已关闭" ;
		}else{
			str="还剩"+day1+"天"+ +hour1+"小时"+ minute1+"分自动关闭" ;
		}
		return str;
	}
}
